// 本地持久化
// userInfo
const USER_KEY = 'hm_shopping_user'
export const getInfo = () => {
  const result = localStorage.getItem(USER_KEY)
  return JSON.parse(result) || { userId: '', token: '' }
}

export const setInfo = (obj) => {
  localStorage.setItem(USER_KEY, JSON.stringify(obj))
}

export const removeInfo = () => {
  localStorage.removeItem(USER_KEY)
}

// 用户搜索历史
const HISTORY_KEY = 'hm_shopping_history'
export const getHistory = () => {
  const result = localStorage.getItem(HISTORY_KEY)
  return JSON.parse(result) || []
}

export const setHistory = (obj) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(obj))
}

export const removeHistory = () => {
  localStorage.removeItem(HISTORY_KEY)
}
